Hello everyone. I've been all the day with a problem and I can't fix it. I hope you can help me.
I have a company which has different areas (for example: Marketing, Sales, etc.) and each area has different employees. Each employee has a name and an age (for example: John, 27)
This are my structs (I just can use this two)
Code:
typedef struct employee{
char name[20];
int age;
struct employee* next;
struct employee* nextAge;
}tEmployee;
typedef struct company{
char area[10];
tEmployee* first; // points to the first of each area
}tCompany;
I don't know how to do the first part of this problem (I suppose I can do the rest on my own). I have to ask for the information and put it in the program.
This is what I think I have to do:
- First, I ask how many areas has the company.
- I ask for memory of that amount of areas (I know I have to use a realloc, I use it a lot of times, but I don't know what to put in NULL so I can use realloc)
- Then, I ask which area has an employee. For example: Area 1 - 2 employees: John (27) and Louis (29)
- I look in the list for the last position so I put there the new node, like this:
Code:
while(company->first!=NULL)
company->first=company->first->sig;
and then I put there the information.
If I only had 1 area, I could do:
Code:
void fillDataOneEmployee(tCompany **company)
{
while(((*company)->first->next)!=NULL)
(*company)->first=(*company)->first->next;
printf("\nName: ");
scanf("%s", ((*company)->first->name));
printf("\nAge: ");
scanf("%s", ((*company)->first->age));
(*company)->first->next=NULL;
}
(this code is for 1 employee)
Then I have to do a lot of things with that but I think I can do that on my own.
Can you help me how to start the program, please?
Thanks!!!!!